<!-- 空白页面参考模版 -->
{extend name='public/base' /}
{block name='content'}
{include file='public/content_header' /}
<section class="content">
    <div class="row">
        <div class="col-md-12">
            <div class="card">
                <!-- 表单头部 -->
                <div class="card-header">
                    <div class="btn-group">
                        <a class="btn flat btn-sm btn-default BackButton">
                            <i class="fas fa-arrow-left"></i>
                            返回
                        </a>
                    </div>
                </div>

                <form class="form-horizontal" role="form" id="dataForm" action="" method="post"
                      enctype="multipart/form-data">
                    <div class="card-body">

                        <div class="form-group row">
                            <label for="parent_id" class="col-sm-2 col-form-label ">父级菜单</label>
                            <div class="col-sm-10 col-md-4 formInputDiv">
                                <select class="form-control select2bs4" id="parent_id" name="parent_id"
                                        data-placeholder="请选择父级菜单">
                                    <option value="0">/</option>
                                    {$parent_list|raw|default=''}
                                </select>
                            </div>
                        </div>
                        <script>
                            $('#parent_id').select2({
                                theme: 'bootstrap4'
                            })
                        </script>

                        <div class="form-group row">
                            <label for="name" class="col-sm-2 col-form-label ">名称</label>
                            <div class="col-sm-10 col-md-4 formInputDiv">
                                <input type="text" class="form-control"
                                       id="name" name="name" value="{$data.name|default=''}"
                                       placeholder="请输入名称">
                            </div>
                        </div>

                        <div class="form-group row">
                            <label for="url" class="col-sm-2 col-form-label ">URL</label>
                            <div class="col-sm-10 col-md-4 formInputDiv">
                                <input type="text" class="form-control"
                                       id="url" name="url" value="{$data.url|default=''}"
                                       placeholder="请输入URL">
                            </div>
                        </div>

                        <div class="form-group row">
                            <label for="sort_number" class="col-sm-2 col-form-label ">排序号</label>
                            <div class="col-sm-10 col-md-4 formInputDiv">
                                <input type="number" class="form-control"
                                       id="sort_number" name="sort_number" value="{$data.sort_number|default='1000'}"
                                       placeholder="请输入排序号">
                            </div>
                        </div>
                        <script>
                            $('#sort_number')
                                .bootstrapNumber({
                                    upClass: 'success',
                                    downClass: 'primary',
                                    center: true
                                });
                        </script>

                        <div class="form-group row">
                            <label for="icon" class="col-sm-2 col-form-label">图标</label>
                            <div class="col-sm-10 col-md-4 formInputDiv">
                                <div class="input-group">
                                    <div class="input-group-prepend">
                                        <span class="input-group-text iconpicker-component">
                                            <i class="far fa-calendar-alt"></i>
                                        </span>
                                    </div>
                                    <input type="text" maxlength="30" id="icon" name="icon"
                                           value="{$data.icon|default='fas fa-list'}" class="form-control "
                                           placeholder="请输入图标class">
                                </div>
                            </div>
                        </div>
                        <script>
                            $('#icon').iconpicker({
                                placement: 'bottomLeft',
                                title: '请选择一个图标',
                                animation:false,
                            });
                        </script>

                        <div class="form-group row">
                            <label for="is_show" class="col-sm-2 col-form-label ">是否显示</label>
                            <div class="col-sm-10 col-md-4 formInputDiv">
                                <input class="switch fieldSwitch" id="is_show" name="is_show"
                                       value="{$data.is_show|default='1'}" hidden/>
                                <input type="checkbox" class="input-switch" id="is_showSwitch" value="1"
                                       {if(!isset($data) ||$data.is_show==1)}checked{/if}/>
                            </div>
                        </div>
                        <script>
                            $('#is_showSwitch').bootstrapSwitch({
                                onColor: 'success',
                                offColor: 'danger',
                                onText: '是',
                                offText: '否',
                                onSwitchChange: function (event, state) {
                                    $('#is_show').val(state ? '1' : '0');
                                }
                            });
                        </script>

                        <div class="form-group row">
                            <label for="log_method" class="col-sm-2 col-form-label ">日志记录方式</label>
                            <div class="col-sm-10 col-md-4 formInputDiv">
                                <select class="form-control select2bs4" id="log_method" name="log_method"
                                        data-placeholder="请选择日志记录方式">
                                    {foreach name='log_method_list' id='item'}
                                    <option value="{$item.id}" {if isset($data)&&$data.log_method==$item.id}selected{/if}>{$item.name}</option>
                                    {/foreach}
                                </select>
                            </div>
                        </div>
                        <script>
                            $('#log_method').select2({
                                theme: 'bootstrap4'
                            })
                        </script>

                        {if isset($data) && $data.parent_id===0}
                        <div class="form-group row">
                            <label for="is_top" class="col-sm-2 col-form-label ">是否为顶部菜单</label>
                            <div class="col-sm-10 col-md-4 formInputDiv">
                                <input class="switch fieldSwitch" id="is_top" name="is_top"
                                       value="{$data.is_top|default='0'}" hidden/>
                                <input type="checkbox" class="input-switch" id="is_topSwitch" value="1"
                                       {if $data.is_top==1}checked{/if}/>
                            </div>
                        </div>
                        <script>
                            $('#is_topSwitch').bootstrapSwitch({
                                onColor: 'success',
                                offColor: 'danger',
                                onText: '是',
                                offText: '否',
                                onSwitchChange: function (event, state) {
                                    $('#is_top').val(state ? '1' : '0');
                                }
                            });
                        </script>
                        {/if}

                    </div>
                    <div class="card-footer">
                        {:token_field()}
                        <div class="row">
                            <div class="col-sm-2">
                            </div>

                            <div class="col-sm-10 col-md-4 formInputDiv">

                                <div class="btn-group">
                                    <button type="submit" class="btn btn-sm btn-primary dataFormSubmit">
                                        保 存
                                    </button>
                                </div>
                                <div class="btn-group">
                                    <button type="reset" class="btn btn-sm btn-default dataFormReset">
                                        重 置
                                    </button>
                                </div>

                                {if !isset($data)}
                                <div class="btn-group float-right createContinueDiv">
                                    <input type="checkbox" class="form-check-input" value="1" id="_create"
                                           name="_create" title="继续添加数据">
                                    <label class="form-check-label" for="_create">继续添加</label>
                                </div>
                                {/if}
                            </div>
                        </div>
                    </div>

                </form>

            </div>
        </div>
    </div>
</section>
<script>
    /** 表单验证 **/
    $('#dataForm').validate({
        rules: {
            'name': {
                required: true,
            },
            'url': {
                required: true,
            },
        },
        messages: {
            'name': {
                required: "名称不能为空",
            },
            'url': {
                required: "URL不能为空",
            },
        }
    });
</script>

{/block}